<?php
/*
 * description：
 * author：wh
 * email：
 * createTime：{2020/4/22} {17:13} 
 */

namespace libraries\wechat\minipro;


use libraries\Tools;
use libraries\wechat\BaseMiniPro;

class Login extends BaseMiniPro
{
    protected $url = 'https://api.weixin.qq.com/sns/jscode2session';

    /**
     * desc：登录凭证校验
     * author：wh
     */
    function code2Session(){

        $code = input('code', '');
        if(empty($code)){
            return json(Tools::set_result(1, '参数错误'));
        }

        $config = new Config();
        $data = [
            'appid'=>$config->appid,
            'secret'=>$config->secret,
            'js_code'=>$code,
            'grant_type'=>'authorization_code'
        ];

        $this->url .= '?'. http_build_query($data);
        dump($this->url);

        $res = Tools::curl_get($this->url);
        dump($res);
    }
}